#ifndef __STD_CODE_RUN_EVENT_HPP__
#define __STD_CODE_RUN_EVENT_HPP__

#include "base_event.hpp"

namespace run_code_event_space {

struct std_code_run_event : base_event<std_code_run_event>  {
    template <class U>
    ProcessStatus execute_impl(run_code_context_t<U>& context, const string& inFile);
};

template <class U>
ProcessStatus std_code_run_event::execute_impl(run_code_context_t<U>& context, const string& inFile) {
    if (!context.judge_type.stdCompileOk) {
        return ProcessStatus{
                    .result = STD_COMPILE_ERROR,
                    .error = "stdFile cannot run"
        };
    }
    const RuncodeParams& params = context.params;
    const U& judge_type = context.judge_type;
    std::string outFile = inFile.substr(0, inFile.size() - 2) + "stdout";
    outFile = langMap["default"]->detect(outFile, params.spjCachePath);
    return general_execution_strategy::run_code<false, U>(
                judge_type.stdCodeInfo.runStr, params.timeLimit, params.memoryLimit, 
                inFile, outFile, 
                judge_type.stdCodeInfo.lang,
                context.params.spjCachePath);
}

}

#endif /* __STD_CODE_RUN_EVENT_HPP__ */
